package com.canbot.u05.activity.presidemode.newcode.bean;

import android.annotation.SuppressLint;
import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.canbot.u05.bean.dance.Content;
import com.canbot.u05.socket.MsgSendUtils;
import com.canbot.u05.socket.MsgType;

import java.util.List;

public class ModuleUtil {
    @SuppressLint("DefaultLocale")
    public static String translateTime(String time) {
        float v = Float.parseFloat(time);
        int data = (int) v;
        return String.format("00:0%d", data);
    }

    public static boolean checkNameExist(String name, List<HostModuleData> hostModuleDataList) {
        if (hostModuleDataList != null && hostModuleDataList.size() > 0) {
            for (HostModuleData hostModuleData : hostModuleDataList) {
                String taskName = hostModuleData.getTaskName();
                if (taskName.trim().equals(name.trim())) {
                    return true;
                }
            }
        }
        return false;
    }

    public static void playDance(DanceBean danceBean) {
/*        MapVoiceAndEyes.VoiceAndEyesInfo info = new MapVoiceAndEyes.VoiceAndEyesInfo("/ai/ai05res/a1/res/audio/dance/" +
                danceBean.getPath(), null,
                danceBean.getActionID());
        MapVoiceAndEyes.playMapVoiceAndEyes(info);*/
        Content content = new Content(danceBean.getActionID(), danceBean.getContent(), danceBean.getTime(), true, 0, "", danceBean.getPath(), danceBean.getContent(),
                "", "", false);
        MsgSendUtils.sendStringMsgToPad2(MsgType.CUSTOM_DANCE_PREVIEW_START, JSON.toJSONString(content));
    }

    public static boolean checkEmpty(HostItemBean hostItemBean) {
        boolean isEmpty = true;
        int itemType = hostItemBean.getItemType();
        switch (itemType) {
            case HostItemBean.ITEM_TYPE_DANCE:
                DanceBean danceBean = hostItemBean.getDanceBean();
                if (danceBean != null) {
                    String content = danceBean.getContent();
                    if (!TextUtils.isEmpty(content)) {
                        isEmpty = false;
                    }
                }
                break;
            case HostItemBean.ITEM_TYPE_NORMAL:
                int count = 0;
                VoiceBean voiceBean = hostItemBean.getVoiceBean();
                if (voiceBean == null || voiceBean.languageType == NModuleType.VOICE_NONE) {
                    count++;
                }
                List<ActionBean> actionBeanList = hostItemBean.getActionBeanList();
                if (actionBeanList != null && actionBeanList.size() > 0) {
                    ActionBean actionBean = actionBeanList.get(0);
                    if (actionBean.actionType == NModuleType.ACTION_NONE) {
                        count++;
                    }
                } else {
                    count++;
                }
                MoveBean moveBean = hostItemBean.getMoveBean();
                if (moveBean == null || moveBean.orientation == EDirection.NONE) {
                    count++;
                }
                PicturnEmotionBean picturnEmotionBean = hostItemBean.getPicturnEmotionBean();
                if (picturnEmotionBean == null || picturnEmotionBean.getType() == NModuleType.PICTURE_NONE) {
                    count++;
                }
                if (count <= 3) {
                    isEmpty = false;
                }
                break;
        }
        return isEmpty;
    }
}
